<html>
<head><meta charset="utf-8"><title>Emit metadata to generated LLVM IR code · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html">Emit metadata to generated LLVM IR code</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232430370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232430370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chuyang Chen <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232430370">(Mar 30 2021 at 14:03)</a>:</h4>
<p>Is there any method to pass metadata, for instance, type names, to the LLVM IR code generated by rustc?<br>
I'm working on a GSoC project that ports an LLVM auto-diff plugin to rust. It needs metadata of the high-level language, but I found no proper way to pass such information to LLVM. The closest thing may be the "plugin" feature, which, however, is unstable. I'm considering to use some tricks like defining global variables who have the same names as the types we need to know. It seems workable (the IR code generated does have the type name strings in names of the global variables), but not elegant. Is there any better way?</p>



<a name="232431507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232431507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232431507">(Mar 30 2021 at 14:10)</a>:</h4>
<blockquote>
<p>the IR code generated does have the type name strings in names of the global variables</p>
</blockquote>
<p>This is not guaranteed. See e.g. <a href="https://github.com/rust-lang/rust/pull/76030">https://github.com/rust-lang/rust/pull/76030</a> which was reverted at some point but will be reintroduced as soon as possible.</p>



<a name="232432412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232432412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chuyang Chen <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232432412">(Mar 30 2021 at 14:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code/near/232431507">said</a>:</p>
<blockquote>
<blockquote>
<p>the IR code generated does have the type name strings in names of the global variables</p>
</blockquote>
<p>This is not guaranteed. See e.g. <a href="https://github.com/rust-lang/rust/pull/76030">https://github.com/rust-lang/rust/pull/76030</a> which was reverted at some point but will be reintroduced as soon as possible.</p>
</blockquote>
<p>Bad news. If there is no proper way to pass metadata, an intrusive modification of the compiler may be needed. However, that will be costly, I think.</p>



<a name="232433851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232433851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232433851">(Mar 30 2021 at 14:25)</a>:</h4>
<p>debuginfo is a form of metadata you could use?</p>



<a name="232433923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232433923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chuyang Chen <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232433923">(Mar 30 2021 at 14:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code/near/232433851">said</a>:</p>
<blockquote>
<p>debuginfo is a form of metadata you could use?</p>
</blockquote>
<p>Yes, sure.</p>



<a name="232436124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232436124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chuyang Chen <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232436124">(Mar 30 2021 at 14:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code/near/232433851">said</a>:</p>
<blockquote>
<p>debuginfo is a form of metadata you could use?</p>
</blockquote>
<p>Do you mean that it could be acceptable to modify the compiler to generate some extra debuginfo in the generated IR, or there has been such method? (Compiling .rs files with "-g" option is not  quite right, I think.)</p>



<a name="232438178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Emit%20metadata%20to%20generated%20LLVM%20IR%20code/near/232438178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Emit.20metadata.20to.20generated.20LLVM.20IR.20code.html#232438178">(Mar 30 2021 at 14:48)</a>:</h4>
<p>The more exhaustive debuginfo that we generate is, the better, I'd say. But it should be something that debuggers don't trip over, of course.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>